package org.lemon.cla.enums;

import ch.qos.logback.core.util.StringUtil;
import com.baomidou.mybatisplus.annotation.IEnum;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import org.lemon.cla.exception.BusinessException;

public enum WeekdayEnum implements IEnum<String> {
    SUNDAY("周日"),
    MONDAY("周一"),
    TUESDAY("周二"),
    WEDNESDAY("周三"),
    THURSDAY("周四"),
    FRIDAY("周五"),
    SATURDAY("周六");

    private final String description;

    WeekdayEnum(String description) {
        this.description = description;
    }

    @Override
    @JsonValue
    public String getValue() {
        return this.description;
    }

    public String getDescription() {
        return description;
    }

    @JsonCreator
    public static WeekdayEnum fromDescription(String description) {
        for (WeekdayEnum weekday : WeekdayEnum.values()) {
            if (weekday.getDescription().equals(description)) {
                return weekday;
            }
        }
        throw new BusinessException(HttpStatusEnum.UNSUPPORTED_TYPE.getCode(),"非法的枚举: "+description);
    }
}